package org.jeecg.modules.API.threadTest;


import org.jeecg.modules.API.ygctpapi.ctp.YGCTP;
import org.jeecg.modules.API.ygctpapi.spi.YGCTPTraderSpi;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.concurrent.Future;
import java.util.concurrent.TimeoutException;

@Service
public class threadserviceimp {

    private static final Logger logger = LoggerFactory.getLogger(threadserviceimp.class);
    @Resource(name = "ygThreadpool")
    private ThreadPoolTaskExecutor executor;

//    @Async("ygThreadpool")
//    public void executeAsync() {
//        logger.info("start executeAsync");
//        try{
//            Thread.sleep(1000);
//        }catch(Exception e){
//            e.printStackTrace();
//        }
//        logger.info("end executeAsync");
//    }


    public void executeAsync() {

        try{
            for(int i = 0;i<60;i++){
                Future<?> future = executor.submit(() -> {
                    logger.info("start executeAsync");
                    try {
                        Thread.sleep(2000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    logger.info("end executeAsync");
                });
                Thread.sleep(1000);
            }

        }catch(Exception e){
            e.printStackTrace();
        }
    }

//    public void executeAsync() throws TimeoutException, IllegalAccessException, NoSuchFieldException, IOException {
//
//        YGCTP ygctp = new YGCTP();
//        YGCTPTraderSpi y =ygctp.getTraderSpiP();
//        System.out.println("asd");
//    }



}
